package com.btl.cygf;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.btl.bean.ZuiXin;
import com.btl.cygf.tool.AppConstant;
import com.btl.cygf.tool.Util;
import com.btl.ui.adapter.MyListView;
import com.btl.utils.DownTuUtils;
import com.btl.utils.TimeUtils;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.tencent.connect.share.QQShare;
import com.tencent.connect.share.QzoneShare;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;
import com.yzx.yunyanzhengdemo.activity.LoginActivity;

public class TieZiActivity extends Activity implements OnClickListener {
	private LinkedList<ZuiXin> listItems = new LinkedList<ZuiXin>(); // 数据源集合
	private LinkedList<ZuiXin> listItems2 = new LinkedList<ZuiXin>(); // 数据源集合
	private MyListAdapter myListAdapter; // 评论 ListView
	private MyListAdapter02 myListAdapter02;// 步骤 ListView
	private AsyncHttpClient client;
	private RequestParams params;
	private String v_id;
	ImageView login_backtofragment;
	ImageView img;
	ImageView dianzanpic;
	TextView dianzanshu;
	TextView title;
	ImageView touxiang;
	TextView zuozhe;
	TextView shijian; // 发布时间
	TextView jianjie; // 简介
	TextView cailiao; // 材料
	TextView address; //地址 
	MyListView step_listView; // 步骤ListView
	MyListView comment_listView; // 评论ListView
	
	LinearLayout address_layout;

	private LinearLayout yincang; // 如果是交换帖的话 那么这个布局隐藏
	private LinearLayout dibu;
	private EditText edit; // 发布的评论
	private ImageView fasong; // 点击发送
	private ImageView tiezi_shoucang;
	private ImageView pinglun;

	private FrameLayout zan_layout;
	Button fabiaopinglun;
	private int state;
	private ImageView fenxiang;
	private ListView menulist;
	private PopupWindow pop;
	private View layout;

	private int shareType = QQShare.SHARE_TO_QQ_TYPE_DEFAULT;
	private String mAppid;
	private Tencent mTencent = null;

	private String sort;// 帖子的分类
	ImageLoader imageLoader = ImageLoader.getInstance();

	SharedPreferences share;

	ZuiXin zuiXin;
	boolean flag = false; // 这是点赞的标志
	boolean flog = false; // 这是发送 的标志
	private String p_id; // 用户的id

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.jinrutiezi);
		Intent intent = getIntent();
		v_id = intent.getStringExtra("v_id");
		String type = intent.getStringExtra("type");

		mAppid = AppConstant.APP_ID;
		// 第一个参数就是上面所说的申请的APPID，第二个是全局的Context上下文，这句话实现了调用QQ登录
		mTencent = Tencent.createInstance(mAppid, getApplicationContext());

		share = getSharedPreferences("login", Activity.MODE_WORLD_READABLE);

		login_backtofragment = (ImageView) findViewById(R.id.login_backtofragment);
		img = (ImageView) findViewById(R.id.img);
		dianzanshu = (TextView) findViewById(R.id.dianzanshu);
		dianzanpic = (ImageView) findViewById(R.id.imageView1);
		title = (TextView) findViewById(R.id.tiezi_title);
		touxiang = (ImageView) findViewById(R.id.tiezi_touxiang);
		zuozhe = (TextView) findViewById(R.id.zuozhe);
		shijian = (TextView) findViewById(R.id.shijian);
		jianjie = (TextView) findViewById(R.id.jianjie);
		cailiao = (TextView) findViewById(R.id.cailiao);
		step_listView = (MyListView) findViewById(R.id.list_buzhou);
		comment_listView = (MyListView) findViewById(R.id.list_pinglun);
		fenxiang = (ImageView) findViewById(R.id.fenxiang);
		pinglun = (ImageView) findViewById(R.id.pinglun);
		fabiaopinglun = (Button) findViewById(R.id.fabiaopinglun);
		yincang = (LinearLayout) findViewById(R.id.yincang);
		dibu = (LinearLayout) findViewById(R.id.dibu);
		
		address = (TextView) findViewById(R.id.address);
		address_layout= (LinearLayout) findViewById(R.id.address_layout);

		share = getSharedPreferences("login", Activity.MODE_WORLD_READABLE);
		p_id = share.getString("id", "");

		edit = (EditText) findViewById(R.id.text1);
		// //设置失去焦点的监听
		// edit.setOnFocusChangeListener(new OnFocusChangeListener() {
		// public void onFocusChange(View v, boolean hasFocus) {
		// if (!hasFocus) {
		// fabiaopinglun.setVisibility(View.VISIBLE);
		// dibu.setVisibility(View.GONE);
		// }
		// }
		// });
		// 内容改变监听
		edit.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				if (edit.getText().toString().length() > 0) {
					fasong.setImageResource(R.drawable.send_d);
					flog = true;
				} else {
					fasong.setImageResource(R.drawable.send_u);
					flog = false;
				}
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub

			}
		});

		fasong = (ImageView) findViewById(R.id.fasong1);
		fasong.setOnClickListener(this);

		if (type == null) {

			img.setFocusable(true);
			img.setFocusableInTouchMode(true);
			img.requestFocus();
		} else {

			comment_listView.setFocusable(true);
			comment_listView.setFocusableInTouchMode(true);
			comment_listView.requestFocus();
		}
		pinglun.setOnClickListener(this);

		tiezi_shoucang = (ImageView) findViewById(R.id.teizi_shoucang);

		tiezi_shoucang.setOnClickListener(this);

		fenxiang.setOnClickListener(this);
		touxiang.setOnClickListener(this);
		fabiaopinglun.setOnClickListener(this);

		zan_layout = (FrameLayout) findViewById(R.id.zan_layout);
		zan_layout.setOnClickListener(this);

		imageLoader.init(DownTuUtils.getConfig(TieZiActivity.this));
		login_backtofragment.setOnClickListener(this);
		/**
		 * 异步加载网络资源信息
		 */
		client = new AsyncHttpClient();
		// 像网络传输的数据
		params = new RequestParams();

		getDataRefresh();

		myListAdapter02 = new MyListAdapter02();
		myListAdapter = new MyListAdapter();

		// listView里添加适配器
		step_listView.setAdapter(myListAdapter02);
		comment_listView.setAdapter(myListAdapter);
		

		params.remove("pid");
		params.remove("vid");

		params.add("pid", share.getString("id", ""));
		params.add("vid", v_id);

		client.post(getResources().getString(R.string.url)
				+ "/CYGF/shou.info", params, new JsonHttpResponseHandler() {

			@Override
			public void onFailure(int statusCode, Header[] headers,
					Throwable throwable, JSONArray errorResponse) {
				// TODO Auto-generated method stub
				super.onFailure(statusCode, headers, throwable, errorResponse);
			}

			@Override
			public void onSuccess(int statusCode, Header[] headers,
					JSONArray response) {

				JSONObject object = response.optJSONObject(0);

				if(object.optString("msg").equals("已收藏")){
					tiezi_shoucang.setImageResource(R.drawable.shoucang_d);
				}
			}

		});
		

	}

	@Override
	public void onClick(View v) {
		InputMethodManager imm = (InputMethodManager) getSystemService(TieZiActivity.this.INPUT_METHOD_SERVICE);
		switch (v.getId()) {
		case R.id.login_backtofragment:
			this.finish();
			break;

		case R.id.fenxiang:
			getshare();
			break;

		case R.id.tiezi_touxiang:
			// Toast.makeText(getApplicationContext(), "点击头像", 1).show();
			Intent it = new Intent(TieZiActivity.this, ZuoZheActivity.class);
			it.putExtra("id", zuiXin.getPid());
			startActivity(it);
			break;

		case R.id.zan_layout:

			updateZan();

			break;
		case R.id.teizi_shoucang:
			shouCang();
			break;

		case R.id.pinglun:
			Intent intent = new Intent();
			intent.putExtra("v_id", v_id);
			intent.setClass(TieZiActivity.this, TieZiPingLunActivity.class);
			startActivity(intent);
			break;
		case R.id.fabiaopinglun:
			fabiaopinglun.setVisibility(View.GONE);
			dibu.setVisibility(View.VISIBLE);
			edit.requestFocus();

			imm.showSoftInput(edit, 0);

			break;
		case R.id.fasong1:

			if (flog) {
				if (!p_id.equals("")) {
					params.remove("p_id");
					params.add("p_id", p_id);
					params.remove("v_id");
					params.add("v_id", v_id + "");
					params.remove("c_content");
					params.add("c_content", edit.getText().toString());
					client.post(getResources().getString(R.string.url)
							+ "/CYGF/commentsend.post", params,
							new JsonHttpResponseHandler() {

								@Override
								public void onSuccess(int statusCode,
										Header[] headers, JSONArray response) {
									JSONObject object = response
											.optJSONObject(0);
									if ("评论成功".equals(object.optString("msg"))) {
										getDataRefresh();
									}
								}
							});

					edit.setText("");

					fabiaopinglun.setVisibility(View.VISIBLE);
					dibu.setVisibility(View.GONE);
					// 隐藏键盘

					imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);

				} else {
					Intent it2 = new Intent();
					it2.putExtra("vid", v_id);
					it2.setClass(TieZiActivity.this, LoginActivity.class);
					startActivity(it2);
				}

			} else {
				// 不做处理
			}
			break;
		}
	}

	/**
	 * 添加收藏的方法
	 */

	private void shouCang() {
		if (share.getString("id", "").equals("")) {
			Intent it = new Intent(TieZiActivity.this, LoginActivity.class);
			it.putExtra("type", "1");
			it.putExtra("vid", v_id);
			startActivity(it);

			return;
		}
		
		tiezi_shoucang.setImageResource(R.drawable.shoucang_d);

		params.remove("pid");
		params.remove("vid");

		params.add("pid", share.getString("id", ""));
		params.add("vid", v_id);

		client.post(getResources().getString(R.string.url)
				+ "/CYGF/shoucang.info", params, new JsonHttpResponseHandler() {

			@Override
			public void onFailure(int statusCode, Header[] headers,
					Throwable throwable, JSONArray errorResponse) {
				// TODO Auto-generated method stub
				super.onFailure(statusCode, headers, throwable, errorResponse);
			}

			@Override
			public void onSuccess(int statusCode, Header[] headers,
					JSONArray response) {

				JSONObject object = response.optJSONObject(0);

				Toast.makeText(getApplicationContext(),
						object.optString("msg"), 1).show();
			}

		});

	}

	/**
	 * 点赞处理方法
	 */
	private void updateZan() {

		if (!flag) {
			params.remove("zan");
			params.add("zan", v_id);
			client.post(getResources().getString(R.string.url)
					+ "/CYGF/updateZan.info", params,
					new JsonHttpResponseHandler());

			dianzanpic.setImageResource(R.drawable.zan_d);
			if (Integer.parseInt(dianzanshu.getText().toString()) > 999) {
				dianzanshu.setText("999+");
			} else {

				dianzanshu.setText(Integer.parseInt(dianzanshu.getText()
						.toString()) + 1 + "");
			}

			flag = true;

		} else {
			params.remove("zan");
			params.add("zan", v_id);
			client.post(getResources().getString(R.string.url)
					+ "/CYGF/removeZan.info", params,
					new JsonHttpResponseHandler());

			dianzanpic.setImageResource(R.drawable.dianzan);

			if (Integer.parseInt(dianzanshu.getText().toString()) > 999) {
				dianzanshu.setText("999+");
			} else {

				dianzanshu.setText(Integer.parseInt(dianzanshu.getText()
						.toString()) - 1 + "");
			}

			flag = false;

		}

	}

	/**
	 * 弹出popup选择分享方式
	 */

	private void getshare() {

		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

		Map<String, Object> map1 = new HashMap<>();
		map1.put("share_iv", R.drawable.qqtubiao);
		map1.put("share_tv", "QQ好友");
		list.add(map1);
		Map<String, Object> map2 = new HashMap<>();
		map2.put("share_iv", R.drawable.qqkongjian);
		map2.put("share_tv", "QQ空间");
		list.add(map2);

		if (state == 1 && pop.isShowing()) {
			state = 0;
			pop.dismiss();
		}

		layout = getLayoutInflater().inflate(R.layout.share, null);
		menulist = (ListView) layout.findViewById(R.id.share_lv);
		SimpleAdapter adapter = new SimpleAdapter(TieZiActivity.this, list,
				R.layout.share_item, new String[] { "share_iv", "share_tv" },
				new int[] { R.id.iv_share, R.id.tv_share });

		menulist.setAdapter(adapter);

		pop = new PopupWindow(layout, img.getWidth(),
				fabiaopinglun.getHeight() * 4 + 10);

		ColorDrawable cd = new ColorDrawable(-0000);
		pop.setBackgroundDrawable(cd);

		pop.update();
		pop.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
		pop.setTouchable(true); // 设置popupwindow可点击
		pop.setOutsideTouchable(true); // 设置popupwindow外部可点击
		pop.setFocusable(true); // 获取焦点

		pop.showAtLocation(layout, (Gravity.CENTER) | (Gravity.CENTER), 0, 0);
		state = 1;

		pop.setTouchInterceptor(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				/**** 如果点击了popupwindow的外部，popupwindow也会消失 ****/
				if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
					pop.dismiss();
					return true;
				}
				return false;
			}

		});

		menulist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				switch (position) {
				case 0:
					shareqq();
					pop.dismiss();
					break;

				case 1:
					shareqqZone();
					pop.dismiss();
					break;

				default:
					break;
				}

			}

		});

	}

	/**
	 * 分享到qq空间
	 */

	private void shareqqZone() {

		final Bundle params = new Bundle();
		params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE,
				QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT);
		params.putString(QzoneShare.SHARE_TO_QQ_TITLE, zuiXin.getTitle());
		params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, zuiXin.getInfo());
		params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL,
				getResources().getString(R.string.url) + "/CYGF/LookPost?vid="
						+ zuiXin.getVid());

		System.out.println(zuiXin.getPicture() + " qq");

		ArrayList<String> imageUrls = new ArrayList<String>();
		imageUrls.add(zuiXin.getPicture());

		params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, imageUrls);

		doShareToQzone(params);

	}

	/**
	 * 分享结果处理
	 */

	IUiListener ShareListener = new IUiListener() {

		@Override
		public void onCancel() {
			Util.toastMessage(TieZiActivity.this, "取消分享");
		}

		@Override
		public void onError(UiError e) {
			// TODO Auto-generated method stub
			Util.toastMessage(TieZiActivity.this, "分享出现错误");
		}

		@Override
		public void onComplete(Object response) {
			// TODO Auto-generated method stub
			Util.toastMessage(TieZiActivity.this, "分享成功");
		}

	};

	/**
	 * 用异步方式启动分享
	 * 
	 * @param params
	 */
	private void doShareToQzone(final Bundle params) {
		final Activity activity = TieZiActivity.this;
		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				mTencent.shareToQzone(activity, params, ShareListener);
			}
		}).start();
	}

	/**
	 * 分享到qq好友
	 */
	private void shareqq() {
		final Bundle params = new Bundle();
		params.putString(QQShare.SHARE_TO_QQ_TITLE, zuiXin.getTitle());
		params.putString(QQShare.SHARE_TO_QQ_TARGET_URL,
				getResources().getString(R.string.url) + "/CYGF/LookPost?vid="
						+ zuiXin.getVid());
		params.putString(QQShare.SHARE_TO_QQ_SUMMARY, zuiXin.getInfo());
		params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, zuiXin.getPicture());
		params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "创意工坊");
		params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, shareType);
		doShareToQQ(params);

	}

	// 启动qq分享

	private void doShareToQQ(final Bundle params) {
		mTencent.shareToQQ(TieZiActivity.this, params, ShareListener);
	}

	/**
	 * 从网络获取数据
	 */
	private void getDataRefresh() {
		params.remove("v_id");
		params.add("v_id", v_id);
		// 实例LinkList数据源

		client.post(getResources().getString(R.string.url)
				+ "/CYGF/sendSingleJason.post", params,
				new JsonHttpResponseHandler() {
					// 链接成功做出的反应
					@Override
					public void onSuccess(int statusCode, Header[] headers,
							JSONArray response) {
						zuiXin = new ZuiXin();
						JSONObject object = response.optJSONObject(0);
						String s1 = object.optString("v_image");
						String s2 = object.optString("v_title");
						String s3 = object.optString("v_cailiao");
						String s4 = object.optString("v_intro");
						String s5 = object.optString("p_id");
						int s6 = object.optInt("v_dianzan");
						String s7 = object.optString("p_nickname");
						String s8 = object.optString("p_avatar");
						String s9 = object.optString("v_date");
						String s11 = object.optString("v_address");
 						sort = object.optString("v_sort");

						System.out.println(sort);
						System.out.println("为了测试这步执行了没有1" + sort);
						if ("交换帖".equals(sort)) {
							System.out.println("为了测试这步执行了没有2");
							yincang.setVisibility(View.GONE);
							address_layout.setVisibility(View.VISIBLE);
						}

						int s10 = object.optInt("v_id");
						zuiXin.setPicture(s1);
						zuiXin.setTitle(s2);
						zuiXin.setCailiao(s3);
						zuiXin.setInfo(s4);
						if (s7 == null) {
							zuiXin.setUsername(s5);
						} else {
							zuiXin.setUsername(s7);
						}

						zuiXin.setPid(s5);

						zuiXin.setDianzan(s6);
						zuiXin.setTouxiang(s8);
						zuiXin.setDate(s9);
						zuiXin.setVid(s10);
						zuiXin.setAddress(s11);
						System.out.println(zuiXin.getPicture());

						imageLoader.displayImage(zuiXin.getPicture(), img,
								DownTuUtils.getOptions());
						// img.setImageResource(R.drawable.advertising_default_1);

						if (s6 > 999) {
							dianzanshu.setText("999+");
						} else {
							dianzanshu.setText(zuiXin.getDianzan() + "");

						}
						title.setText(zuiXin.getTitle());
						imageLoader.displayImage(s8, touxiang,
								DownTuUtils.getOptions2());
						zuozhe.setText(zuiXin.getUsername());
						shijian.setText(TimeUtils.getDate(zuiXin.getDate()));
						jianjie.setText(zuiXin.getInfo());
						cailiao.setText(zuiXin.getCailiao());
						address.setText(zuiXin.getAddress());
						// // listItems.addFirst(zuiXin);
						// zuiXin = null;
						super.onSuccess(statusCode, headers, response);
					}

					// 链接网络失败，做出的反应
					@Override
					public void onFailure(int statusCode, Header[] headers,
							Throwable throwable, JSONArray errorResponse) {
						super.onFailure(statusCode, headers, throwable,
								errorResponse);
					}
				});

		/**
		 * 获取帖子步骤
		 */
		listItems = new LinkedList<ZuiXin>();// 清空数据
		client.post(getResources().getString(R.string.url)
				+ "/CYGF/sendStepJason.post", params,
				new JsonHttpResponseHandler() {
					// 链接成功做出的反应
					@Override
					public void onSuccess(int statusCode, Header[] headers,
							JSONArray response) {
						for (int i = 0; i < response.length(); i++) {
							ZuiXin zuiXin = new ZuiXin();
							JSONObject object = response.optJSONObject(i);
							String s1 = object.optString("s_step");
							String s2 = object.optString("s_image");
							String s3 = object.optString("s_content");
							zuiXin.setStepshu(s1);
							zuiXin.setSteppic(s2);
							zuiXin.setStepcontent(s3);
							listItems.add(zuiXin);
							// imageLoader.DisplayImage(zuiXin.getPicture(),
							// img);
							// img.setImageResource(R.drawable.advertising_default_1);
							// listItems.addFirst(zuiXin);
						}
						int w = listItems.size();
						// BaseAdapter数据发生改变
						myListAdapter02.notifyDataSetChanged();
						super.onSuccess(statusCode, headers, response);
					}

					// 链接网络失败，做出的反应
					@Override
					public void onFailure(int statusCode, Header[] headers,
							Throwable throwable, JSONArray errorResponse) {
						super.onFailure(statusCode, headers, throwable,
								errorResponse);
					}
				});

		/**
		 * 获取帖子评论
		 */
		listItems2 = new LinkedList<ZuiXin>();// 清空数据

		client.post(getResources().getString(R.string.url)
				+ "/CYGF/sendCommentJason.post", params,
				new JsonHttpResponseHandler() {
					// 链接成功做出的反应
					@Override
					public void onSuccess(int statusCode, Header[] headers,
							JSONArray response) {
						for (int i = 0; i < response.length(); i++) {
							ZuiXin zuiXin = new ZuiXin();
							JSONObject object = response.optJSONObject(i);
							String s2 = object.optString("c_content");
							String s3 = object.optString("c_time");
							String s4 = object.optString("p_id");
							String s5 = object.optString("p_nickname");
							String s6 = object.optString("p_avatar");
							int s7 = object.optInt("v_id");
							zuiXin.setVid(s7);
							zuiXin.setTouxiang(s6);
							zuiXin.setContent(s2);
							zuiXin.setDatepinlun(s3);
							if (s5 == null) {
								zuiXin.setComuser(s4);
							} else {
								zuiXin.setComuser(s5);
							}

							zuiXin.setPid(s4);
							listItems2.add(zuiXin);
							// imageLoader.DisplayImage(zuiXin.getPicture(),
							// img);
							// img.setImageResource(R.drawable.advertising_default_1);
							// listItems.addFirst(zuiXin);
						}
						// BaseAdapter数据发生改变
						int i = listItems2.size();
						myListAdapter.notifyDataSetChanged();
						super.onSuccess(statusCode, headers, response);
					}

					// 链接网络失败，做出的反应
					@Override
					public void onFailure(int statusCode, Header[] headers,
							Throwable throwable, JSONArray errorResponse) {
						super.onFailure(statusCode, headers, throwable,
								errorResponse);
					}
				});

	}

	/**
	 * listview的适配器MyListAdapter 存放步骤
	 */
	private class MyListAdapter02 extends BaseAdapter {

		class ListItemView {
			public ImageView image;
			public TextView step;
			public TextView content;
		}

		@Override
		public int getCount() {
			return listItems.size();
		}

		@Override
		public Object getItem(int position) {

			return listItems.get(position);
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			// final int selectID = position;
			// 自定义视图
			ListItemView listItemView = null;
			if (convertView == null) {
				listItemView = new ListItemView();
				// 获取list_item布局文件的视图
				convertView = LayoutInflater.from(getApplicationContext())
						.inflate(R.layout.buzhou_item_layout, null);
				// 获取控件对象
				listItemView.image = (ImageView) convertView
						.findViewById(R.id.img);
				listItemView.step = (TextView) convertView
						.findViewById(R.id.step_id);
				listItemView.content = (TextView) convertView
						.findViewById(R.id.content);
				// 设置控件集到convertView
				convertView.setTag(listItemView);
			} else {
				listItemView = (ListItemView) convertView.getTag();
			}
			// 设置文字和图片
			ImageLoader imageLoader = ImageLoader.getInstance();
			imageLoader.init(DownTuUtils.getConfig(TieZiActivity.this));
			imageLoader.displayImage(listItems.get(position).getSteppic(),
					listItemView.image, DownTuUtils.getOptions());
			// listItemView.image.setImageBitmap(new
			// BitmapFactory().decodeByteArray(data, offset, length))
			listItemView.step.setText(listItems.get(position).getStepshu());
			listItemView.content.setText(listItems.get(position)
					.getStepcontent());
			return convertView;
		}
	}

	/**
	 * listview的适配器MyListAdapter 存放评论
	 */
	private class MyListAdapter extends BaseAdapter {

		class ListItemView {
			public ImageView image;
			public TextView username;
			public TextView time;
			public TextView comment;
		}

		@Override
		public int getCount() {
			return listItems2.size();
		}

		@Override
		public Object getItem(int position) {

			return listItems2.get(position);
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			// final int selectID = position;
			// 自定义视图
			ListItemView listItemView = null;
			if (convertView == null) {
				listItemView = new ListItemView();
				// 获取list_item布局文件的视图
				convertView = LayoutInflater.from(getApplicationContext())
						.inflate(R.layout.pinglun_item_layout, null);
				// 获取控件对象
				listItemView.image = (ImageView) convertView
						.findViewById(R.id.touxiang);
				listItemView.username = (TextView) convertView
						.findViewById(R.id.title);
				listItemView.time = (TextView) convertView
						.findViewById(R.id.time);
				listItemView.comment = (TextView) convertView
						.findViewById(R.id.pinglunneiron);

				// 设置控件集到convertView
				convertView.setTag(listItemView);
			} else {
				listItemView = (ListItemView) convertView.getTag();
			}

			// 设置文字和图片
			// listItemView.image.setImageDrawable(getResources().getDrawable(R.drawable.advertising_default_1));
			// listItemView.image.setImageBitmap(new
			// BitmapFactory().decodeByteArray(data, offset, length))
			System.out.println("评论" + listItems2.get(position).getTouxiang());
			imageLoader.displayImage(listItems2.get(position).getTouxiang(),
					listItemView.image, DownTuUtils.getOptions2());

			listItemView.image.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent it = new Intent(TieZiActivity.this,
							ZuoZheActivity.class);
					it.putExtra("id", listItems2.get(position).getPid() + "");
					startActivity(it);
				}
			});

			// listItemView.image.setImageResource(R.drawable.advertising_default_1);
			listItemView.username
					.setText(listItems2.get(position).getComuser());
			listItemView.time.setText(TimeUtils.getDate(listItems2
					.get(position).getDatepinlun()));
			listItemView.comment.setText(listItems2.get(position).getContent());
			return convertView;
		}
	}

}
